package org.chen.spring;

import org.chen.spring.aop.factory.AspectFactory;
import org.chen.spring.core.factory.BeanFactory;

/**
 * 应用程序上下文
 *
 * @author Chen
 * @since 2023/6/7 12:18
 */
public class ChenApplicationContext {

    private static final BeanFactory BEAN_FACTORY;


    static {
        BEAN_FACTORY = new BeanFactory();
    }

    public ChenApplicationContext(Class<?> clazz) {
        BeanFactory.registerBean(BEAN_FACTORY.getClass().getSimpleName(), BEAN_FACTORY);
        BeanFactory.registerBean(this.getClass().getSimpleName(), this);
        AspectFactory aspectFactory = new AspectFactory();
        aspectFactory.initAspect(clazz);
        BeanFactory.registerBean(aspectFactory.getClass().getSimpleName(), aspectFactory);
        BEAN_FACTORY.initBean(clazz);

    }

    public static BeanFactory getBeanFactory() {
        return BEAN_FACTORY;
    }
}
